// @dart = 2.12
import 'package:floor/floor.dart';
import 'package:ls_work/sql/app_data_base.dart';
import 'package:ls_work/sql/protral/patrol_task_dao.dart';

class AppDbUtils{

  static AppDbUtils? _instance;

  factory AppDbUtils.instance() => _instance??=AppDbUtils._();

  AppDbUtils._();

  void dispose() => _instance = null;

  late final AppDataBase _db;

  PatrolTaskDao get patrolTaskDao => _db.patrolTaskDao;

  Future<void> initDb() async {
    _db = await $FloorAppDataBase.databaseBuilder("app_data_base.db").addMigrations([
      // migration1to2,
      // migration2to3
    ]).build();
  }
  
  final migration1to2 = Migration(1,2,(database) async{
    await database.execute('ALERT TABLE PatrolTaskData ADD COLUMN taskDate TEXT');
  });

  final migration2to3 = Migration(2,3,(database) async{
    await database.execute('ALERT TABLE PatrolTaskPointData ADD COLUMN taskName');

  });
}